#include <bits/stdc++.h>
#include <vector>
using namespace std;


#define isNum(x) ('0'<=x && x<='9')
#define ctos(x) (x-'0')
#define BP(i, j) (i/3*3 + j/3)
class Solution {

bool flag_row[9][10]{false};
bool flag_col[9][10]{false};
bool flag_block[9][10]{false};
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        bool isValid = true;
        for(int i=0; i<9; ++i){
            for(int j=0; j<9; ++j){
                const char& chr = board[i][j];
                if(!isNum(chr)) continue;
                if(!flag_row[i][ctos(chr)]) flag_row[i][ctos(chr)] = true;
                else {isValid = false; break;}
                if(!flag_col[j][ctos(chr)]) flag_col[j][ctos(chr)] = true;
                else {isValid = false; break;}
                if(!flag_block[BP(i, j)][ctos(chr)]) flag_block[BP(i, j)][ctos(chr)] = true;
                else {isValid = false; break;}
            }
        }
        return isValid;
    }
};

int main(){
    vector<vector<char>> board = {{'.','.','.','.','5','.','.','1','.'},{'.','4','.','3','.','.','.','.','.'},{'.','.','.','.','.','3','.','.','1'},{'8','.','.','.','.','.','.','2','.'},{'.','.','2','.','7','.','.','.','.'},{'.','1','5','.','.','.','.','.','.'},{'.','.','.','.','.','2','.','.','.'},{'.','2','.','9','.','.','.','.','.'},{'.','.','4','.','.','.','.','.','.'}};
    Solution solution;
    auto ans = solution.isValidSudoku(board);
    return 0;
}